package com.xgq.drink.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xgq.drink.entity.FavoriteProduct;
import com.xgq.drink.mapper.FavoriteProductMapper;
import com.xgq.drink.service.IFavoriteProductService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

@Service
public class FavoriteProductServiceImpl extends ServiceImpl<FavoriteProductMapper, FavoriteProduct> implements IFavoriteProductService {

    /**
     * 检查是否已收藏该商品
     */
    @Override
    public boolean isFavoriteProduct(Long userId, Long productId) {
        return baseMapper.selectCountByUserIdAndProductId(userId, productId) > 0;
    }
    @Override
    public int logicDeleteByUserIdAndFavoriteProductId(Long userId, Long favoriteProductId) {
        QueryWrapper<FavoriteProduct> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id", userId);
        queryWrapper.eq("product_id", favoriteProductId);
        // 获取收藏商品列表
        FavoriteProduct favoriteProductPage = baseMapper.selectOne(queryWrapper);
        favoriteProductPage.setIsDel(1);
        return baseMapper.updateById(favoriteProductPage);
    }
}